package com.tucc.hello.leetcode.common;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode.common
 * @date 2021/5/28
 **/
public class ListNode {
    public int val;
    public ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    public static ListNode of(int... nums){
        if(nums == null || nums.length == 0){
            return null;
        }
        ListNode head = new ListNode();
        head.val = nums[0];
        ListNode tail = head;
        for(int i = 1;i < nums.length;i ++){
            tail.next = new ListNode();
            tail.next.val = nums[i];
            tail = tail.next;
        }
        return head;
    }

    public static void print(ListNode listNode){
        while(listNode != null){
            System.out.print(listNode.val + " ");
            listNode = listNode.next;
        }
        System.out.println();
    }
}
